<%-- 
    Document   : GestionCompte
    Created on : 2012-03-24, 17:58:07
    Author     : Étienne
--%>

<%@page import="application.beans.SectionBean"%>
<%@page import="java.util.ResourceBundle"%>
<%@page import="java.util.Locale"%>
<%@page import="application.beans.CoursBean"%>
<%@page import="java.util.Map"%>
<%@page import="java.math.BigDecimal"%>
<%@page import="java.util.HashMap"%>
<%@page import="application.beans.CompteBean"%>
<%@page import="java.util.List"%>
<%@page import="controleur.ConstantesWeb"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
    Locale currentLocale = Locale.FRENCH;
    ResourceBundle strings = ResourceBundle.getBundle("StringsBundle", currentLocale);
    
    List<CompteBean> resultats = (List<CompteBean>)session.getAttribute(ConstantesWeb.ATTRIBUT_RESULTAT_GESTION_COMPTE);
    // On va chercher le numéro de page
    Integer numPage = (Integer)session.getAttribute(ConstantesWeb.PARAM_NUM_PAGE);
    
    // On va chercher les listes constantes
    HashMap<Integer,String> domaines = (HashMap<Integer,String>)session.getAttribute(ConstantesWeb.ATTRIBUT_DOMAINES);
    HashMap<Integer,String> statuts = (HashMap<Integer,String>)session.getAttribute(ConstantesWeb.ATTRIBUT_STATUTS);
%>
<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="CSS/styleGestion.css" type="text/css"/>
        <link rel="stylesheet" href="CSS/styleGeneral.css" type="text/css"/>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><%= strings.getString("gestionCompte") %></title> 
        <script type="text/javascript" src="Scripts/jQuery.js"></script>
        <script type="text/javascript" src="Scripts/scriptsCommun.js"></script>
        <script type="text/javascript" src="Scripts/scriptsAJAX.js"></script>
        <script type="text/javascript" src="Scripts/scriptsGestionCompte.js"></script>
    </head>
    <body>
        <%@include file="header.jsp" %>
        <div id="corps">
             <div id="navigation">
                <ol class="nav">
                    <li><a id="hover" class="active" href="./Accueil"><%=strings.getString("NavigationAccueil")%></a></li>
                    <%if(utilisateur != null && utilisateur.getStatut().equals("administrateur")){%>
                        <li><a class="active" href="./GestionCompte"><%=strings.getString("NavigationCompte")%></a></li>
                        <li><a class="active" href="./GestionCours"><%=strings.getString("NavigationCours")%></a></li>
                    <%}%>
                    <li><a class="active" href="aide.jsp"><%=strings.getString("NavigationAide")%></a></li>
                </ol>
            </div>
            <div class="hoverMenu" id="sections">
                <ol>
                    <%for(int i = 0; i < sections.size(); i++){%>
                    <li>
                        <%= sections.get(i).getTitre().concat((sections.get(i).getSousSections().size() > 0)?"   >":"")  %>
                        <% if(sections.get(i).getSousSections().size() != 0){%>
                        <div class="hoverMenu">
                            <ol>
                                <%for(int j = 0; j < sections.get(i).getSousSections().size(); j++){%>
                                <li class="liSousSection" id="<%=j%>">
                                    <form id="formSousSection<%=j%>" action="./SousSection" method="get">
                                        <span>
                                            <%= sections.get(i).getSousSections().get(j).getTitre().concat((sections.get(i).getSousSections().get(j).getDiscussions().size() > 0)?"   >":"")  %>
                                            <input type="hidden" name="<%= ConstantesWeb.PARAM_ID_SOUS_SECTION %>" value="<%= sections.get(i).getSousSections().get(j).getIdSousSection() %>"/>
                                        </span>
                                    </form>
                                    <%if(sections.get(i).getSousSections().get(j).getDiscussions().size() != 0){%>
                                    <div class="hoverMenu">
                                        <ol>
                                            <%for(int k = 0; k < sections.get(i).getSousSections().get(j).getDiscussions().size(); k++){%>
                                            <li class="liDiscussion" id="<%=k%>">
                                                <form id="formDiscussion<%=k%>" action="./Discussion" method="get">
                                                    <span>
                                                        <%= sections.get(i).getSousSections().get(j).getDiscussions().get(k).getTitre() %>
                                                        <input type="hidden" name="<%= ConstantesWeb.PARAM_ID_DISCUSSION %>" value="<%= sections.get(i).getSousSections().get(j).getDiscussions().get(k).getIdDiscussion() %>"/>
                                                    </span>
                                                </form>
                                            </li>
                                            <%}%>
                                        </ol>
                                    </div>
                                    <%}%>
                                </li>  
                                <%}%>
                            </ol>
                        </div>
                        <%}%>
                    </li>  
                    <%}%>
                </ol>
            </div>
            <div id="centre" class="tailleMain">
                <form id="formRecherche" action="./RechercheGestionCompte" method="post">
                    <table id="espRecherche" class="taillePetit alignTop fullWidth">
                        <tr>
                            <td><%= strings.getString("gestionCompteUsername") %></td>
                            <td><input type="text" id="<%=ConstantesWeb.PARAM_RECH_USERNAME%>" name="<%=ConstantesWeb.PARAM_RECH_USERNAME%>" class="critere"/></td>
                            <td><%= strings.getString("gestionCompteSexe") %></td>
                            <td>
                                <select id="<%=ConstantesWeb.PARAM_RECH_SEXE%>" name="<%=ConstantesWeb.PARAM_RECH_SEXE%>" class="critere">
                                    <option value=""></option>
                                    <option value="M"><%= strings.getString("gestionCompteM") %></option>
                                    <option value="F"><%= strings.getString("gestionCompteF") %></option>
                                </select>
                            </td>
                            <td><%= strings.getString("gestionCompteDomaine") %></td>
                            <td>
                                <select id="<%=ConstantesWeb.PARAM_RECH_DOMAINE%>" name="<%=ConstantesWeb.PARAM_RECH_DOMAINE%>" class="critere">
                                <option value=""></option>
                                <%for(Map.Entry<Integer,String> domaine:domaines.entrySet()){%>
                                <option value="<%=domaine.getValue()%>"><%=domaine.getValue()%></option>
                                <%}%>
                                </select>
                            </td>
                            <td rowspan="2"><input id="btnRecherche" type="button" value="Rechercher"/></td>
                        </tr>
                        <tr>
                            <td><%= strings.getString("gestionCompteName") %></td>
                            <td><input type="text" id="<%=ConstantesWeb.PARAM_RECH_NOM%>" name="<%=ConstantesWeb.PARAM_RECH_NOM%>" class="critere"/></td>
                            <td><%= strings.getString("gestionCompteCode") %></td>
                            <td> <input type="text" id="<%=ConstantesWeb.PARAM_RECH_CODE%>" name="<%=ConstantesWeb.PARAM_RECH_CODE%>" class="critere"/></td>
                            <td><%= strings.getString("gestionCompteStatut") %></td>
                            <td>
                                <select id="<%=ConstantesWeb.PARAM_RECH_STATUT%>" name="<%=ConstantesWeb.PARAM_RECH_STATUT%>" class="critere">
                                <option value=""></option>
                                <%for(Map.Entry<Integer,String> statut:statuts.entrySet()){%>
                                <option value="<%=statut.getValue()%>"><%=statut.getValue()%></option>
                                <%}%>
                                </select>
                            </td>
                        </tr>
                    </table>
                </form>
                <form id="formResultats" action="./SauvegarderComptes" method="post">
                    <table id="espResultats" class="taillePetit fullWidth">
                        <tr class="teteResultat">
                            <td class="titreResultat colCheck"></td>
                            <td class="titreResultat colUsername"><%= strings.getString("gestionCompteColUsername") %></td>
                            <td class="titreResultat colPrenom"><%= strings.getString("gestionCompteColPrenom") %></td>
                            <td class="titreResultat colNom"><%= strings.getString("gestionCompteColNom") %></td>
                            <td class="titreResultat"><%= strings.getString("gestionCompteColCode") %></td>
                            <td class="titreResultat colSexe"><%= strings.getString("gestionCompteColSexe") %></td>
                            <td class="titreResultat colCourriel"><%= strings.getString("gestionCompteColCourriel") %></td>
                            <td class="titreResultat colDomaine"><%= strings.getString("gestionCompteColDomaine") %></td>
                            <td class="titreResultat colStatut"><%= strings.getString("gestionCompteColStatut") %></td>
                            <td class="titreResultat colActif"><%= strings.getString("gestionCompteColActif") %></td>
                        </tr>
                        <%if(resultats.isEmpty()){%>
                        <tr class="fullWidth"><td colspan="9" class="alignCenter fullWidth"><%= strings.getString("gestionCompteAucunRes") %></td></tr>
                        <%}else{%>
                            <%for(int i = ((numPage - 1) * 20); i < (numPage * 20 - 1); i++){%>
                                <%if(i < resultats.size()){
                                    CompteBean compte = resultats.get(i);
                            %>
                            <tr class="unCompte">
                            <td>
                                <input name="identifiant<%=compte.getIdCompte()%>" type="hidden" value="<%=compte.getIdCompte()%>"/>
                                <input name="choisi<%=compte.getIdCompte()%>" id="chk<%=compte.getIdCompte()%>" class="chkCompte" type="checkbox"/>
                                <ul id="lstCours<%=compte.getIdCompte()%>" class="elemCache">
                                    <%for(CoursBean cours: compte.getCours()){%>
                                    <li id="<%=cours.getTitre() + compte.getIdCompte()%>" idCours="<%=cours.getIdCours()%>"><%=cours.getTitre()%></li>
                                    <%}%>
                                </ul>
                            </td>
                            <td><input type="hidden" name="username<%=compte.getIdCompte()%>" value="<%=compte.getUsername()%>"/><label for="chk<%=compte.getIdCompte()%>"><%=compte.getUsername()%></label></td>
                            <td><input type="text" name="prenom<%=compte.getIdCompte()%>" value="<%=compte.getPrenom()%>" class="noSubmitEnter" maxlength="50" size="15"/></td>
                            <td><input type="text" name="nom<%=compte.getIdCompte()%>" value="<%=compte.getNom()%>" class="noSubmitEnter" maxlength="50" size="15"/></td>
                            <td><input type="text" name="code<%=compte.getIdCompte()%>" value="<%=compte.getCodePermanent()%>" class="noSubmitEnter" maxlength="15" size="15"/></td>
                            <td>
                                <select name="sexe<%=compte.getIdCompte()%>">
                                    <option value="" <%if(compte.getSexe().equals("")){%>selected<%}%>></option>
                                    <option value="M" <%if(compte.getSexe().equals("M")){%>selected<%}%>><%= strings.getString("gestionCompteM") %></option>
                                                <option value="F" <%if(compte.getSexe().equals("F")){%>selected<%}%>><%= strings.getString("gestionCompteF") %></option>
                                </select>
                            </td>
                            <td><input type="text" name="courriel<%=compte.getIdCompte()%>" value="<%=compte.getCourriel()%>" class="noSubmitEnter" maxlength="100" size="15"/></td>

                            <td>
                                <select name="domaine<%=compte.getIdCompte()%>">
                                    <option value=""></option>
                                    <%for(Map.Entry<Integer,String> domaine:domaines.entrySet()){%>
                                    <option value="<%=domaine.getValue()%>" <%if(compte.getDomaineEtude().equals(domaine.getValue())){%>selected<%}%>><%=domaine.getValue()%></option>
                                    <%}%>
                                </select>
                            </td>
                            <td>
                                <select id="statut<%=compte.getIdCompte()%>" name="statut<%=compte.getIdCompte()%>">
                                    <option value=""></option>
                                    <%for(Map.Entry<Integer,String> statut:statuts.entrySet()){%>
                                    <option value="<%=statut.getValue()%>" <%if(compte.getStatut().equals(statut.getValue())){%>selected<%}%>><%=statut.getValue()%></option>
                                    <%}%>
                                </select>
                            </td>
                            <td>
                                <%if(compte.getIdCompte() != utilisateur.getIdCompte()){%>
                                <select name="actif<%=compte.getIdCompte()%>">
                                    <option value="O" <%if(compte.getActif().equals("O")){%>selected<%}%>><%= strings.getString("gestionCompteOui") %></option>
                                                <option value="N" <%if(compte.getActif().equals("N")){%>selected<%}%>><%= strings.getString("gestionCompteNon") %></option>
                                </select>
                                <%}else{%>
                                    <input type="hidden" name="actif<%=compte.getIdCompte()%>" value="<%=compte.getActif()%>">
                                    <%=compte.getActif().equals("O") ? strings.getString("gestionCompteOui"):strings.getString("gestionCompteNon")%>
                                <%}%>
                            </td>
                            </tr>
                            <%}else{%>
                                <tr class="messageVide">
                                    <td colspan="4">&nbsp;</td>
                                </tr>
                            <%}
                        }
                        }%>
                        <tr>
                            <td class="fullWidth alignRight taillePetit alignMiddle" colspan="10">
                                Comptes <%=numPage * 20 - 19%>-<%=numPage * 20%>&nbsp;&nbsp;
                                <img id="prevComptes" class="pointer" src="Images/Button-Previous-icon.png"/>&nbsp;
                                <img id="nextComptes" class="pointer" src="Images/Button-Next-icon.png"/>&nbsp;&nbsp;&nbsp;
                            </td>
                        </tr>
                    </table>
                    <div class="fullWidth">
                        <input type="button" id="btnNouveau" class="alignCenter pointer" value="Nouveau compte"/>
                        <input type="submit" id="btnSauvegarder" class="alignCenter pointer" value="<%= strings.getString("gestionCompteBtnSauv") %>" <%if(resultats.isEmpty()){%>disabled<%}%> />
                        <input type="button" id="btnInscription" class="alignCenter pointer" value="<%= strings.getString("gestionCompteBtnGererCours") %>" <%if(resultats.isEmpty()){%>disabled<%}%>/>         
                    </div>
                </form>
            </div>
        </div>
        <div id="espNouvCompte" class="elemCache popUp">
            <form id="formNouveauCompte" action="./CreationCompte" method="post">
                <table class="fullWidth">
                    <thead>
                        <tr>
                            <td><%= strings.getString("gestionCompteCreation") %><span class="pointer annulerNouveau right">[x]</span></td>
                        </tr>
                    </thead>
                    <tbody class="taillePetit">
                        <tr>
                            <td><span id="errNouvVide" class="taillePetit elemCache"><em><%= strings.getString("gestionCompteCreationErrVide") %></em></span>&nbsp;</td>
                        </tr>
                        <tr>
                        <td><%= strings.getString("gestionCompteCreationUsername") %><em>*</em>: <span id="errUsername" class="elemCache"><em><%= strings.getString("gestionCompteCreationErrUsername") %></em></span> <input id="nouveauUsername" name="nouveauUsername" type="text" class="infoNouveau fullWidth noSubmitEnter" maxlength="50"/></td>
                        </tr>
                        <tr>
                            <td><%= strings.getString("gestionCompteCreationPrenom") %><em>*</em>: <input id="nouveauPrenom" name="nouveauPrenom" type="text" class="infoNouveau fullWidth noSubmitEnter" maxlength="50"/></td>
                        </tr>
                        <tr>
                            <td><%= strings.getString("gestionCompteCreationNom") %><em>*</em>: <input id="nouveauNom" name="nouveauNom" type="text" class="infoNouveau fullWidth noSubmitEnter" maxlength="50"/></td>
                        </tr>
                        <tr>
                            <td><%= strings.getString("gestionCompteCreationPassword") %><em>*</em>: <span id="errPassword" class="elemCache"><em><%= strings.getString("gestionCompteCreationErrPass") %></em></span> <input id="nouveauPassword" name="nouveauPassword" type="password" class="infoNouveau fullWidth noSubmitEnter" maxlength="50"/></td>
                        </tr>
                        <tr>
                            <td><%= strings.getString("gestionCompteCreationRePassword") %><em>*</em>: <input id="nouveauVerifPassword" name="nouveauVerifPassword" type="password" class="fullWidth noSubmitEnter" maxlength="50"/></td>
                        </tr>
                        <tr>
                            <td><%= strings.getString("gestionCompteCreationCode") %><input id="nouveauCode" name="nouveauCode" type="text" class="fullWidth noSubmitEnter" maxlength="15"/></td>
                        </tr>
                        <tr>
                            <td><%= strings.getString("gestionCompteCreationCourriel") %><em>*</em>: <span id="errCourriel" class="elemCache"><em><%= strings.getString("gestionCompteCreationErrCourriel") %></em></span><input id="nouveauCourriel" name="nouveauCourriel" type="text" class="infoNouveau fullWidth" maxlength="100"/></td>
                        </tr>
                        <tr>
                            <td>
                                <%= strings.getString("gestionCompteCreationSexe") %><em>*</em>:
                                <select id="nouveauSexe" name="nouveauSexe" class="fullWidth">
                                    <option value="M"><%= strings.getString("gestionCompteM") %></option>
                                    <option value="F"><%= strings.getString("gestionCompteF") %></option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <%= strings.getString("gestionCompteCreationDomaine") %><em>*</em>:
                                <select id="nouveauDomaine" name="nouveauDomaine" class="fullWidth">
                                    <%for(Map.Entry<Integer,String> domaine:domaines.entrySet()){%>
                                    <option value="<%=domaine.getValue()%>"><%=domaine.getValue()%></option>
                                    <%}%>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <%= strings.getString("gestionCompteCreationStatut") %><em>*</em>:
                                <select id="nouveauStatut" name="nouveauStatut" class="fullWidth">
                                    <%for(Map.Entry<Integer,String> statut:statuts.entrySet()){%>
                                    <option value="<%=statut.getValue()%>"><%=statut.getValue()%></option>
                                    <%}%>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td><span><em>*</em><%= strings.getString("gestionCompteObligatoires") %></span></td>
                        </tr>
                        <tr class="fullWidth">
                            <td class="alignCenter">
                                <input type="button" id="btnAccepterNouveau" value="<%= strings.getString("gestionCompteBtnAccepter") %>" class="pointer"/>
                                <input type="button" class="annulerNouveau pointer" value="<%= strings.getString("gestionCompteBtnAnnuler") %>"/>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </form>
        </div>
        <div id="espInscription" class="popUp">
            <form id="formInscription" action="./ConnecterCompteACours" method="post">
                <table class="fullWidth fullHeight">
                    <thead>
                        <tr>
                            <td colspan ="2"><%= strings.getString("gestionCompteInscription") %><span class="pointer annulerInscription right">[x]</span></td>
                        </tr>
                    </thead>
                    <tbody class="taillePetit">
                        <tr>
                            <td colspan="2">
                                <%= strings.getString("gestionCompteInscriptionNom") %><input id="txtRecherche" type="text"> 
                                <%= strings.getString("gestionCompteInscriptionDomaine") %>
                                <select id="domaineInscription" name="domaine">
                                    <%for(Map.Entry<Integer,String> domaine:domaines.entrySet()){%>
                                    <option value="<%=domaine.getValue()%>"><%=domaine.getValue()%></option>
                                    <%}%>
                                </select>
                                <input id="btnRechercher" type="button" value="<%= strings.getString("gestionCompteBtnRechercher") %>"/>
                            </td>
                        </tr>
                        <tr>
                            <td  class="alignTop tailleInscr">
                                <span class="bold taillePetit alignCenter"><%= strings.getString("gestionCompteInscriptionResultats") %></span><br/>
                                <ul id="resultatsRecherche" class="noBulletList"></ul>
                            </td>
                            <td id="espListChoix" class="borderLeft tailleInscr alignTop">
                                <span class="bold taillePetit alignCenter"><%= strings.getString("gestionCompteInscriptionInscrits") %></span><br/>
                                <ul id="choixRecherche" class="noBulletList"></ul>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" class="fullWidth alignCenter">
                                <input type="hidden" id="idCompteInscription" name="idCompte"/>
                                <input id="accepterCours" type="button" value="<%= strings.getString("gestionCompteBtnSauv") %>"/>
                                <input class="annulerInscription" type="button" value="<%= strings.getString("gestionCompteBtnAnnuler") %>"/>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </form>
        </div>
        <div id="espDisable" class="disable"></div>     
        <form id="formChangementPage" action="./ChangementPage" method="post">
            <input type="hidden" name="<%=ConstantesWeb.PARAM_NEXT%>" value="<%=ConstantesWeb.ATTRIBUT_PAGE_GESTIONCOMPTE%>"/>
            <input type="hidden" id="numPage" name="<%=ConstantesWeb.PARAM_NUM_PAGE%>" value="<%=numPage%>"/>
            <input type="hidden" id="totComptes" value="<%=resultats.size()%>"/>
        </form>
        <input type="hidden" id="gestionCompteAlertSelect" value="<%=strings.getString("gestionCompteAlertSelect")%>"/>
        <input type="hidden" id="gestionCompteAlertErr" value="<%=strings.getString("gestionCompteAlertErr")%>"/>
        <input type="hidden" id="gestionCompteAlertInscription" value="<%=strings.getString("gestionCompteAlertInscription")%>"/>
    </body>
</html>
